package String.s2;

public class test_1071 {
    public static void main(String[] args) {

    }

}
class Solution {
    public String gcdOfStrings(String str1, String str2) {
        int s1=str1.length();
        int s2=str2.length();
        int t=gcd(s1,s2);
        String s=str1.substring(0,t);
        if(check(s,str1)&&check(s,str2)){
           return s;
        }
        return "";
    }
    public Boolean check(String t,String s){
        int lenx=s.length()/t.length();
        StringBuilder sb=new StringBuilder();
        for(int i=0;i<lenx;i++){
            sb.append(t);
        }
        return sb.toString().equals(s);
    }
    public int gcd(int str1,int str2){
        int b=str1%str2;
        while(b!=0){
            str1=str2;
            str2=b;
            b=str1%str2;
        }
        return str2;
    }
}